package manager;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import data.dao.*;
import data.dto.*;
import data.searchdto.*;
import data.dao.daoFactory.*;
import data.dao.daoImplementation.NotFoundException;

public class LeaveTypeManager {
	private LeaveTypeDAO leaveTypeDAO;
	private NatureOfLeaveDAO natureOfLeaveDAO;
	private CompensationConsumedDAO compensationConsumedDAO;

	private ArrayList<LeaveTypeDTO> leaveTypelist;
	private ArrayList<CompensationLeaveUserDetails> CompensationLeaveUserDetailslist;
	private ArrayList<CompensationConsumedDTO> compensationConsumedDetialList;

	public LeaveTypeManager() {
		this.leaveTypeDAO = LeaveFactory.loadInstance().getLeaveTypeDAO();
		this.compensationConsumedDAO = LeaveFactory.loadInstance()
				.getCompensationConsumedDAO();
		this.natureOfLeaveDAO = LeaveFactory.loadInstance().getNatureOfLeaveDAO();
	}

	public ArrayList<LeaveTypeDTO> findAllLeaveType() throws LeaveDAOException,
			SQLException, data.dao.daoImplementation.SQLException {
		leaveTypelist = new ArrayList<LeaveTypeDTO>();
		try {
			leaveTypelist = leaveTypeDAO.findAllLeaveType();
		} catch (LeaveDAOException e) {
			e.printStackTrace();
		}
		return leaveTypelist;
	}

	public ArrayList<LeaveTypeDTO> findAllLeaveTypeDisplay()
			throws LeaveDAOException, SQLException,
			data.dao.daoImplementation.SQLException {
		leaveTypelist = new ArrayList<LeaveTypeDTO>();
		try {
			leaveTypelist = this.findAllLeaveType();
		} catch (LeaveDAOException e) {
			e.printStackTrace();
		}
		
		LeaveTypeDTO leaveType = new LeaveTypeDTO();
		leaveType.setId(0);
		leaveType.setName("Choose Leave Type");
		leaveTypelist.add(0, leaveType);
		
		return leaveTypelist;
	}

	public ArrayList<LeaveTypeDTO> findLeaveType(short id)
			throws LeaveDAOException, java.sql.SQLException, SQLException {
		leaveTypelist = new ArrayList<LeaveTypeDTO>();
		try {
			leaveTypelist = leaveTypeDAO.findLeaveType(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return leaveTypelist;
	}

	public void insertLeaveDetailType(LeaveTypeDTO LeaveDetail)
			throws LeaveDAOException, SQLException,
			data.dao.daoImplementation.SQLException {
		try {
			leaveTypeDAO.insertLeaveDetailType(LeaveDetail);
		} catch (LeaveDAOException e) {
			e.printStackTrace();
		}

	}

	public void updateLeaveDetailType(LeaveTypeDTO LeaveDetail)
			throws LeaveDAOException, SQLException, NotFoundException,
			data.dao.daoImplementation.SQLException {
		try {
			leaveTypeDAO.updateLeaveDetailType(LeaveDetail);
		} catch (LeaveDAOException e) {
			e.printStackTrace();
		}

	}

	public void deleteLeaveDetailType(LeaveTypeDTO LeaveDetail)
			throws LeaveDAOException, SQLException, NotFoundException,
			data.dao.daoImplementation.SQLException {
		try {
			leaveTypeDAO.deleteLeaveDetailType(LeaveDetail);
		} catch (LeaveDAOException e) {
			e.printStackTrace();
		}

	}

	public ArrayList<CompensationLeaveUserDetails> findCompensationLeave(
			CompensationConsumedSearchDTO compensationconsumedSearchDTO)
			throws LeaveDAOException, NotFoundException {
		CompensationLeaveUserDetailslist = new ArrayList<CompensationLeaveUserDetails>();
		try {
			try {
				CompensationLeaveUserDetailslist = compensationConsumedDAO
						.findCompensationLeave(compensationconsumedSearchDTO);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (LeaveDAOException e) {
			e.printStackTrace();
		}
		return CompensationLeaveUserDetailslist;
	}

	public ArrayList<CompensationLeaveUserDetails> findAllCompensationLeave()
			throws LeaveDAOException {
		CompensationLeaveUserDetailslist = new ArrayList<CompensationLeaveUserDetails>();
		try {
			try {
				CompensationLeaveUserDetailslist = compensationConsumedDAO
						.findAllCompensationLeave();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (LeaveDAOException e) {
			e.printStackTrace();
		}
		return CompensationLeaveUserDetailslist;
	}

	public void insertCompensationLeave(
			CompensationConsumedDTO compensationconsumedDTO)
			throws LeaveDAOException, SQLException {
		try {
			compensationConsumedDAO
					.insertCompensationLeave(compensationconsumedDTO);
		} catch (LeaveDAOException e) {
			e.printStackTrace();
		}

	}

	public void updateCompensationLeave(
			CompensationConsumedDTO compensationconsumedDTO)
			throws LeaveDAOException, SQLException, NotFoundException {
		try {
			compensationConsumedDAO
					.updateCompensationLeave(compensationconsumedDTO);
		} catch (LeaveDAOException e) {
			e.printStackTrace();
		}

	}

	public void deleteCompensationLeave(
			CompensationConsumedDTO compensationconsumedDTO)
			throws LeaveDAOException, SQLException, NotFoundException {
		try {
			compensationConsumedDAO
					.deleteCompensationLeave(compensationconsumedDTO);
		} catch (LeaveDAOException e) {
			e.printStackTrace();
		}

	}

	// Added By thazin win
	public ArrayList<CompensationConsumedDTO> findCompensationDetailByID(
			CompensationConsumedDTO compensationConsumedDTO)
			throws LeaveDAOException, SQLException, NotFoundException {
		compensationConsumedDetialList = new ArrayList<CompensationConsumedDTO>();
		try {
			try {
				compensationConsumedDetialList = compensationConsumedDAO
						.findCompensationDetailByID(compensationConsumedDTO);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (LeaveDAOException e) {
			e.printStackTrace();
		}
		return compensationConsumedDetialList;
	}
	
	public ArrayList<NatureOfLeaveDTO> findAllNatureOfLeave(){
		ArrayList<NatureOfLeaveDTO> lists = new ArrayList<NatureOfLeaveDTO>();
		
		try {
			lists = natureOfLeaveDAO.findAllNatureOfLeave();
		} catch (LeaveDAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (data.dao.daoImplementation.SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return lists;
	}
	
	public ArrayList<NatureOfLeaveDTO> findAllNatureOfLeaveDisplay(){
		ArrayList<NatureOfLeaveDTO> lists = new ArrayList<NatureOfLeaveDTO>();
		
		lists = this.findAllNatureOfLeave();
		
		NatureOfLeaveDTO natureOfLeave = new NatureOfLeaveDTO();
		natureOfLeave.setId(0);
		natureOfLeave.setName("Choose Nature Of Leave");
		
		lists.add(0, natureOfLeave);
				
		return lists;
	}
}
